package cn.funnyxb.powerremember.uis.task.done.autobrow;

import android.content.Intent;
import android.os.AsyncTask;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
import cn.funnyxb.powerremember.beans.ATask;
import cn.funnyxb.powerremember.beans.AWord;
import cn.funnyxb.powerremember.db.AllTableHolders;
import cn.funnyxb.powerremember.db.tables.Tbholder_studyLog;
import cn.funnyxb.powerremember.db.tables.Tbholder_taskWithWords;
import cn.funnyxb.powerremember.tts.TTSHolder;
import cn.funnyxb.powerremember.tts.TTSHolder.NotifyOnceHelper;
import cn.funnyxb.powerremember.uis.task.done.InputIntentChecker;
import cn.funnyxb.powerremember.uis.task.done.Webservices;
import cn.funnyxb.tools.appFrame.App;
import cn.funnyxb.tools.appFrame.activityFrame.AbstractProccessor;
import cn.funnyxb.tools.appFrame.debugTool.Debuger;
import java.util.ArrayList;
import java.util.HashMap;

public class Proccessor_AutoBrow extends AbstractProccessor
  implements IProccessor_AutoBrow
{
  private PlayTask autoPlayTask;
  private AutoBrowConfiger config = null;
  private ContentController contentController;
  private HandPlay handPlayTask;
  private InputIntentChecker intentChecker;
  private TTSHolder.NotifyOnceHelper notifyOnceHelper = new TTSHolder.NotifyOnceHelper()
  {
    public void ttsIsNotSupported()
    {
      Proccessor_AutoBrow.this.ttsBusying = false;
    }
  };
  HashMap<String, String> params = null;
  private int state = 1;
  private Tbholder_taskWithWords tbholder;
  private volatile boolean ttsBusying = false;
  private IUI_AutoBrow ui;

  public Proccessor_AutoBrow(IUI_AutoBrow paramIUI_AutoBrow)
  {
    this.ui = paramIUI_AutoBrow;
  }

  private void asynQuerrySentence(int paramInt, String paramString)
  {
    log("asynQuerrySentence to querry");
    new AsyncTask(paramString, paramInt)
    {
      ArrayList<String> sents = null;

      protected Void doInBackground(Void[] paramArrayOfVoid)
      {
        Proccessor_AutoBrow.this.regAsyncTask(this);
        this.sents = Proccessor_AutoBrow.this.onlineQuerySentence(this.val$word);
        return null;
      }

      protected void onPostExecute(Void paramVoid)
      {
        super.onPostExecute(paramVoid);
        Proccessor_AutoBrow.this.log("down sentence complete,sentence=" + this.sents);
        if (this.sents != null)
        {
          Proccessor_AutoBrow.this.log("notify UI sentence downloaded!");
          Proccessor_AutoBrow.this.ui.notifySentencesLoaded(this.val$id, this.sents);
        }
        Proccessor_AutoBrow.this.unRegAsyncTask(this);
      }
    }
    .execute(new Void[0]);
  }

  private boolean checkIntentDataIsValid(Intent paramIntent)
  {
    this.intentChecker = new InputIntentChecker(paramIntent);
    return this.intentChecker.checkInputIsValid();
  }

  private void loadConfig()
  {
    this.config = AutoBrowConfiger.getConfig(App.getApp());
  }

  private void log(String paramString)
  {
    Debuger.log("proc_autobrow", paramString);
  }

  private String makeDifficultySqlfilter(ArrayList<Integer> paramArrayList)
  {
    if ((paramArrayList == null) || (paramArrayList.size() == 0));
    String str2;
    for (String str1 = ""; ; str1 = " difficulty in ( " + str2.substring(1, str2.length() - 1) + " )")
    {
      return str1;
      str2 = paramArrayList.toString();
    }
  }

  private void notifyUiShowAllBasicInfo(AWord paramAWord)
  {
    this.ui.notifyShowWord(paramAWord.getWord());
    this.ui.notifyShowPhonetic(paramAWord.getPhonetic());
    this.ui.notifyShowMeaning(paramAWord.getMeaning());
  }

  private void notifyUiShowSentence()
  {
    if (!(this.config.isAutoQueryOnline()))
      return;
    this.ui.notifyShowSentences();
  }

  private ArrayList<String> onlineQuerySentence(String paramString)
  {
    log("chaxun webservice");
    ArrayList localArrayList1;
    try
    {
      ArrayList localArrayList2 = Webservices.getSentences(App.getApp(), paramString);
      localArrayList1 = localArrayList2;
      return localArrayList1;
    }
    catch (Exception localException)
    {
      localArrayList1 = null;
    }
  }

  private void proccessAutoSpeechWhenHandMode(AWord paramAWord)
  {
    int i = this.config.getAutoSpeechTimesWhenHandmode();
    if (i <= 0)
      return;
    String str = "";
    for (int j = 0; ; ++j)
    {
      if (j >= i)
        speech(str);
      str = str + paramAWord.getWord() + " 。";
    }
  }

  private void proccessWordLoadedWhenHandMode(AWord paramAWord)
  {
    if (paramAWord == null);
    while (true)
    {
      return;
      this.ui.notifyWordInfo(paramAWord);
      if (this.config.isAutoQueryOnline())
        asynQuerrySentence(paramAWord.getId(), paramAWord.getWord());
      switch (this.state)
      {
      case 2:
      default:
        break;
      case 1:
        notifyUiShowAllBasicInfo(paramAWord);
        notifyUiShowSentence();
        proccessAutoSpeechWhenHandMode(paramAWord);
        break;
      case 3:
      }
      notifyUiShowAllBasicInfo(paramAWord);
      notifyUiShowSentence();
      proccessAutoSpeechWhenHandMode(paramAWord);
    }
  }

  private void speech(String paramString)
  {
    log("speech=" + paramString);
    if (this.params == null)
    {
      this.params = new HashMap();
      this.params.put("utteranceId", "theUtId");
    }
    TextToSpeech localTextToSpeech = App.getApp().getTTSHolder().getTextToSpeech();
    int i = -1;
    if (localTextToSpeech != null)
    {
      this.ttsBusying = true;
      i = App.getApp().getTTSHolder().getTextToSpeech().setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener()
      {
        public void onUtteranceCompleted(String paramString)
        {
          Proccessor_AutoBrow.this.log("onUtteranceCompleted,utteranceId=" + paramString);
          Proccessor_AutoBrow.this.ttsBusying = false;
        }
      });
    }
    App.getApp().getTTSHolder().speech(App.getApp(), this.notifyOnceHelper, paramString, 0, this.params);
    log("listen set to " + i + ",err=" + -1 + ",succ=" + 0);
  }

  public void asyncPrepare(Intent paramIntent)
  {
    new AsyncTask(paramIntent)
    {
      final int state_intent_error = -1;
      final int state_intent_ok = 1;
      AWord word;

      protected Void doInBackground(Void[] paramArrayOfVoid)
      {
        if (Proccessor_AutoBrow.this.checkIntentDataIsValid(this.val$intent) == 0)
        {
          Integer[] arrayOfInteger2 = new Integer[1];
          arrayOfInteger2[0] = Integer.valueOf(-1);
          publishProgress(arrayOfInteger2);
        }
        while (true)
        {
          return null;
          Integer[] arrayOfInteger1 = new Integer[1];
          arrayOfInteger1[0] = Integer.valueOf(1);
          publishProgress(arrayOfInteger1);
          Proccessor_AutoBrow.this.loadConfig();
          Proccessor_AutoBrow.this.tbholder = new Tbholder_taskWithWords(App.getApp().getDBHolder(), Proccessor_AutoBrow.this.intentChecker.getTaskInfo().getName());
          Proccessor_AutoBrow.this.log("range,start 2 end=" + Proccessor_AutoBrow.this.intentChecker.getWordStart() + " - " + Proccessor_AutoBrow.this.intentChecker.getWordEnd());
          Proccessor_AutoBrow.this.contentController = new ContentController(Proccessor_AutoBrow.this.intentChecker.getWordStart(), Proccessor_AutoBrow.this.intentChecker.getWordEnd(), Proccessor_AutoBrow.this.tbholder, null);
          this.word = Proccessor_AutoBrow.this.contentController.getNextWord();
        }
      }

      protected void onPostExecute(Void paramVoid)
      {
        super.onPostExecute(paramVoid);
        if (Proccessor_AutoBrow.this.tbholder == null)
          Proccessor_AutoBrow.this.unRegAsyncTask(this);
        while (true)
        {
          return;
          Proccessor_AutoBrow.this.ui.notifyConfig(Proccessor_AutoBrow.this.config);
          Proccessor_AutoBrow.this.ui.notifyPrepareWorkCompleted();
          if (this.word != null)
            Proccessor_AutoBrow.this.proccessWordLoadedWhenHandMode(this.word);
          Proccessor_AutoBrow.this.unRegAsyncTask(this);
        }
      }

      protected void onPreExecute()
      {
        super.onPreExecute();
        Proccessor_AutoBrow.this.regAsyncTask(this);
        Proccessor_AutoBrow.this.ui.notifyWaitingLoadData();
      }

      protected void onProgressUpdate(Integer[] paramArrayOfInteger)
      {
        super.onProgressUpdate(paramArrayOfInteger);
        switch (paramArrayOfInteger[0].intValue())
        {
        case 0:
        default:
        case -1:
        case 1:
        }
        while (true)
        {
          return;
          Proccessor_AutoBrow.this.ui.notifyErrCall();
          continue;
          Proccessor_AutoBrow.this.ui.notifyIntentOk(Proccessor_AutoBrow.this.intentChecker);
        }
      }
    }
    .execute(new Void[0]);
  }

  public void destroy()
  {
    if (this.autoPlayTask != null)
    {
      this.autoPlayTask.cancel(true);
      this.autoPlayTask.stopImediately = true;
    }
    if (this.handPlayTask != null)
    {
      this.handPlayTask.cancel(true);
      this.handPlayTask.stopImediately = true;
    }
    super.releaseResource();
  }

  public ArrayList<Integer> getDifficultys()
  {
    if (this.config == null);
    for (ArrayList localArrayList = null; ; localArrayList = this.config.getDifficultys())
      return localArrayList;
  }

  public void getFirst()
  {
    this.contentController.reset2Head();
    proccessWordLoadedWhenHandMode(this.contentController.getNextWord());
  }

  public void getNext()
  {
    if (this.handPlayTask == null)
    {
      this.handPlayTask = new HandPlay(null);
      HandPlay localHandPlay = this.handPlayTask;
      Boolean[] arrayOfBoolean = new Boolean[1];
      arrayOfBoolean[0] = Boolean.valueOf(true);
      localHandPlay.execute(arrayOfBoolean);
    }
    while (true)
    {
      return;
      this.handPlayTask.handPlayNext(true);
    }
  }

  public void getPre()
  {
    if (this.handPlayTask == null)
    {
      this.handPlayTask = new HandPlay(null);
      HandPlay localHandPlay = this.handPlayTask;
      Boolean[] arrayOfBoolean = new Boolean[1];
      arrayOfBoolean[0] = Boolean.valueOf(false);
      localHandPlay.execute(arrayOfBoolean);
    }
    while (true)
    {
      return;
      this.handPlayTask.handPlayNext(false);
    }
  }

  public int getState()
  {
    return this.state;
  }

  public void notifyDifficultySetChange(ArrayList<Integer> paramArrayList)
  {
    String str1 = makeDifficultySqlfilter(paramArrayList);
    log("difficultySqlFilter=" + str1);
    String str2 = this.contentController.getSqlFilter();
    this.config.setDifficultys(paramArrayList);
    if ((str2 != null) && (str2.equals(str1)));
    while (true)
    {
      return;
      this.contentController.setSqlFilter(str1);
      this.contentController.resetWithDirect();
      if (this.contentController.getCountOfThisUnit() <= 0)
        this.ui.notifyNoWordSuit();
      this.ui.notifyConfig(this.config);
      if (this.state != 2)
        proccessWordLoadedWhenHandMode(this.contentController.getNextWord());
      pause();
      this.contentController.resetWithDirect();
      play();
    }
  }

  public void notifyStudyLog(long paramLong1, long paramLong2)
  {
    log("studylog");
    Tbholder_studyLog localTbholder_studyLog = App.getApp().getAllTableHolders().getTbholder_studyLog();
    if (localTbholder_studyLog == null);
    while (true)
    {
      return;
      localTbholder_studyLog.log(this.intentChecker.getTaskInfo().getId(), this.intentChecker.getGroupId(), this.intentChecker.getStudyTpye(), paramLong1, paramLong2);
    }
  }

  public void pause()
  {
    log("pause");
    if (this.autoPlayTask == null);
    while (true)
    {
      return;
      this.state = 3;
      if (this.autoPlayTask.isCancelled())
        continue;
      try
      {
        speech("");
        label36: this.autoPlayTask.stopImediately = true;
        this.autoPlayTask.cancel(true);
        this.autoPlayTask = null;
      }
      catch (Exception localException)
      {
        break label36:
      }
    }
  }

  public void play()
  {
    log("play");
    if (this.autoPlayTask == null)
    {
      this.autoPlayTask = new PlayTask(null);
      log("to excute");
      this.autoPlayTask.execute(new Void[0]);
      this.state = 2;
    }
    while (true)
    {
      return;
      if (!(this.autoPlayTask.isCancelled()))
        this.autoPlayTask.cancel(true);
      this.autoPlayTask = null;
      play();
    }
  }

  public void querrySentence(int paramInt, String paramString)
  {
    this.ui.notifyShowSentences();
    asynQuerrySentence(paramInt, paramString);
  }

  public void requestSpeechWord(String paramString)
  {
    if ((this.state == 2) || (!(this.config.isSpeechOnClickWhenHandMode())))
      return;
    speech(paramString);
  }

  public void updateDifficulty(int paramInt1, int paramInt2)
  {
    this.tbholder.updateDifficulty(paramInt1, paramInt2);
  }

  private class HandPlay extends AsyncTask<Boolean, AWord, Void>
  {
    volatile boolean forward = true;
    volatile boolean hasWork2Do = true;
    volatile boolean stopImediately = false;

    protected Void doInBackground(Boolean[] paramArrayOfBoolean)
    {
      Proccessor_AutoBrow.this.regAsyncTask(this);
      if (paramArrayOfBoolean != null)
        this.forward = paramArrayOfBoolean[0].booleanValue();
      while (true)
      {
        label22: if (this.stopImediately);
        AWord localAWord;
        do
        {
          do
            while (true)
            {
              Proccessor_AutoBrow.this.log("at 5");
              return null;
              if (this.hasWork2Do)
                break;
              try
              {
                Thread.sleep(100L);
              }
              catch (Exception localException)
              {
              }
            }
          while (this.stopImediately);
          this.hasWork2Do = false;
          if (this.forward);
          for (localAWord = Proccessor_AutoBrow.this.contentController.getNextWord(); localAWord == null; localAWord = Proccessor_AutoBrow.this.contentController.getPreWord())
          {
            Proccessor_AutoBrow.this.log("click too busy");
            break label22:
          }
        }
        while (this.stopImediately);
        AWord[] arrayOfAWord = new AWord[1];
        arrayOfAWord[0] = localAWord;
        publishProgress(arrayOfAWord);
      }
    }

    public void handPlayNext(boolean paramBoolean)
    {
      Proccessor_AutoBrow.this.log("handplaynext,forward=" + paramBoolean);
      this.forward = paramBoolean;
      this.hasWork2Do = true;
    }

    protected void onPostExecute(Void paramVoid)
    {
      super.onPostExecute(paramVoid);
      Proccessor_AutoBrow.this.log("handplay complete");
      Proccessor_AutoBrow.this.unRegAsyncTask(this);
    }

    protected void onProgressUpdate(AWord[] paramArrayOfAWord)
    {
      super.onProgressUpdate(paramArrayOfAWord);
      Proccessor_AutoBrow.this.log("handplay progess");
      Proccessor_AutoBrow.this.proccessWordLoadedWhenHandMode(paramArrayOfAWord[0]);
    }
  }

  private class PlayTask extends AsyncTask<Void, Integer, Void>
  {
    final int publish_2callAsyncQuerySentence = 350;
    final int publish_allCompleted = 700;
    final int publish_showMeaning = 200;
    final int publish_showPhonetic = 300;
    final int publish_showSentence = 600;
    final int publish_showword = 100;
    final int publish_speech_char = 500;
    final int publish_speech_word = 400;
    final int publish_stopImediately = 800;
    final int publish_wordInfoGetted = 20;
    volatile boolean stopImediately = false;
    volatile AWord word;

    private void doCmd(Integer paramInteger)
    {
      switch (paramInteger.intValue())
      {
      default:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      }
      while (true)
      {
        return;
        try
        {
          Thread.sleep(1000L);
        }
        catch (Exception localException2)
        {
        }
        continue;
        try
        {
          Thread.sleep(500L);
        }
        catch (Exception localException1)
        {
        }
        continue;
        Integer[] arrayOfInteger6 = new Integer[1];
        arrayOfInteger6[0] = Integer.valueOf(100);
        publishProgress(arrayOfInteger6);
        continue;
        Integer[] arrayOfInteger5 = new Integer[1];
        arrayOfInteger5[0] = Integer.valueOf(300);
        publishProgress(arrayOfInteger5);
        continue;
        Integer[] arrayOfInteger4 = new Integer[1];
        arrayOfInteger4[0] = Integer.valueOf(200);
        publishProgress(arrayOfInteger4);
        continue;
        Integer[] arrayOfInteger3 = new Integer[1];
        arrayOfInteger3[0] = Integer.valueOf(600);
        publishProgress(arrayOfInteger3);
        continue;
        Proccessor_AutoBrow.this.ttsBusying = true;
        Integer[] arrayOfInteger2 = new Integer[1];
        arrayOfInteger2[0] = Integer.valueOf(400);
        publishProgress(arrayOfInteger2);
        continue;
        Proccessor_AutoBrow.this.ttsBusying = true;
        Integer[] arrayOfInteger1 = new Integer[1];
        arrayOfInteger1[0] = Integer.valueOf(500);
        publishProgress(arrayOfInteger1);
      }
    }

    private void speechChars(String paramString)
    {
      char[] arrayOfChar = paramString.toCharArray();
      String str = "";
      int i = arrayOfChar.length;
      int j = 0;
      if (j >= i)
      {
        label15: Proccessor_AutoBrow.this.speech(str);
        return;
      }
      char c = arrayOfChar[j];
      if ((c == 'A') || (c == 'a'));
      for (str = str + " ei " + " ------------ "; ; str = str + c + " ------------ ")
      {
        ++j;
        break label15:
      }
    }

    protected Void doInBackground(Void[] paramArrayOfVoid)
    {
      Proccessor_AutoBrow.this.regAsyncTask(this);
      Proccessor_AutoBrow.this.log("prepare 2 play");
      Proccessor_AutoBrow.this.config.getTaskQueneCopy();
      int i = 0;
      if ((i != 0) && (!(Proccessor_AutoBrow.this.contentController.hasMoreWithDirect())))
      {
        label30: Integer[] arrayOfInteger6 = new Integer[1];
        arrayOfInteger6[0] = Integer.valueOf(700);
        publishProgress(arrayOfInteger6);
      }
      while (true)
      {
        label69: return null;
        if (i == 0)
          if (Proccessor_AutoBrow.this.contentController.isInRange())
          {
            this.word = Proccessor_AutoBrow.this.contentController.getCurrentWord();
            label102: i = 1;
          }
        while (true)
        {
          Proccessor_AutoBrow.this.log("get word =" + this.word);
          if (this.word != null)
            break;
          Proccessor_AutoBrow.this.log("get word is null");
          break label69:
          this.word = Proccessor_AutoBrow.this.contentController.getNextWithDirect();
          break label102:
          this.word = Proccessor_AutoBrow.this.contentController.getNextWithDirect();
        }
        if (!(this.stopImediately))
          break;
        Proccessor_AutoBrow.this.log("stopImediately!");
        Integer[] arrayOfInteger5 = new Integer[1];
        arrayOfInteger5[0] = Integer.valueOf(800);
        publishProgress(arrayOfInteger5);
      }
      Proccessor_AutoBrow.this.log("to publish word=" + this.word.getWord());
      Integer[] arrayOfInteger1 = new Integer[1];
      arrayOfInteger1[0] = Integer.valueOf(20);
      publishProgress(arrayOfInteger1);
      AutoBrowConfiger.TaskQuene localTaskQuene = Proccessor_AutoBrow.this.config.getTaskQueneCopy();
      if (localTaskQuene.isExistShowSentenceTaskWhenAutoBrow())
      {
        Integer[] arrayOfInteger4 = new Integer[1];
        arrayOfInteger4[0] = Integer.valueOf(350);
        publishProgress(arrayOfInteger4);
      }
      if (!(localTaskQuene.hasNext()));
      Integer localInteger;
      do
      {
        Proccessor_AutoBrow.this.log("word complete1=" + this.word.getWord());
        break label30:
        if (this.stopImediately)
        {
          Proccessor_AutoBrow.this.log("stopImediately!");
          Integer[] arrayOfInteger3 = new Integer[1];
          arrayOfInteger3[0] = Integer.valueOf(800);
          publishProgress(arrayOfInteger3);
        }
        localInteger = localTaskQuene.getHead();
      }
      while (localInteger == null);
      Proccessor_AutoBrow.this.log("cmd=" + localInteger + ",cn=" + AutoBrowConfiger.ACTIONNAMES[localInteger.intValue()]);
      doCmd(localInteger);
      Proccessor_AutoBrow.this.log("ttsbusing out=" + Proccessor_AutoBrow.this.ttsBusying);
      while (true)
      {
        if (!(Proccessor_AutoBrow.this.ttsBusying))
        {
          if (this.stopImediately);
          Proccessor_AutoBrow.this.log("stopImediately!");
          Integer[] arrayOfInteger2 = new Integer[1];
          arrayOfInteger2[0] = Integer.valueOf(800);
          publishProgress(arrayOfInteger2);
        }
        Proccessor_AutoBrow.this.log("ttsbusing in =" + Proccessor_AutoBrow.this.ttsBusying);
        try
        {
          Thread.sleep(100L);
        }
        catch (Exception localException)
        {
        }
      }
    }

    protected void onCancelled()
    {
      this.stopImediately = true;
      super.onCancelled();
    }

    protected void onPostExecute(Void paramVoid)
    {
      super.onPostExecute(paramVoid);
      Proccessor_AutoBrow.this.unRegAsyncTask(this);
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      super.onProgressUpdate(paramArrayOfInteger);
      switch (paramArrayOfInteger[0].intValue())
      {
      default:
      case 20:
      case 100:
      case 300:
      case 600:
      case 200:
      case 350:
      case 400:
      case 500:
      case 700:
      case 800:
      }
      while (true)
      {
        return;
        Proccessor_AutoBrow.this.ui.notifyWordInfo(this.word);
        continue;
        Proccessor_AutoBrow.this.ui.notifyShowWord(this.word.getWord());
        continue;
        Proccessor_AutoBrow.this.ui.notifyShowPhonetic(this.word.getPhonetic());
        continue;
        Proccessor_AutoBrow.this.ui.notifyShowSentences();
        continue;
        Proccessor_AutoBrow.this.ui.notifyShowMeaning(this.word.getMeaning());
        continue;
        Proccessor_AutoBrow.this.asynQuerrySentence(this.word.getId(), this.word.getWord());
        continue;
        Proccessor_AutoBrow.this.speech(this.word.getWord());
        continue;
        speechChars(this.word.getWord().toUpperCase());
        continue;
        Proccessor_AutoBrow.this.state = 3;
        Proccessor_AutoBrow.this.ui.notifyAutoPlayCompleted();
        continue;
        if (this.word == null)
          continue;
        Proccessor_AutoBrow.this.notifyUiShowAllBasicInfo(this.word);
        Proccessor_AutoBrow.this.notifyUiShowSentence();
        Proccessor_AutoBrow.this.ui.notifyAutoPlayInterruptted();
      }
    }
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.powerremember.uis.task.done.autobrow.Proccessor_AutoBrow
 * JD-Core Version:    0.5.3
 */